package giftmail.util;

public class RunnableDemo implements Runnable {

//	private Thread t;//线程
//	private String threadName;//线程
//	
//	
//	//线程构建
//	public RunnableDemo(String name) {
//		this.threadName = name;
//		System.out.println("Create " + threadName);
//	}
//
//	@Override
//	public void run() {
//		System.out.println("Running " + threadName);
//		try {
//			for(int i = 4; i>0;i--){
//				System.out.println("Thread: " + threadName + ", " + i);
//				//线程sleep
//				Thread.sleep(50);
//			}
//		} catch (Exception e) {
//			System.out.println("Thread " +  threadName + " interrupted.");
//		}
//		System.out.println("Thread " +  threadName + " exiting.");
//	}
//
//	public void start(){
//		System.out.println("Starting " + threadName);
//		if( t == null){
//			t = new Thread (this, threadName);
//			t.start();
//		}
//		
//	}
//	
//	
//	public static void main(String[] args) {
//		RunnableDemo R1 = new RunnableDemo("Thread-1");
//		R1.start();
//		
//		RunnableDemo R2 = new RunnableDemo( "Thread-2");
//	      R2.start();
//	}

	//========================================
	
	@Override
	public void run() {
		for(int i = 0;i<3;i++){
			System.out.println(Thread.currentThread().getName());
		}
		
	}
	
	public static void main(String[] args) {
		RunnableDemo rd = new RunnableDemo();
		new Thread(rd,"A").start();
		new Thread(rd,"B").start();
		new Thread(rd).start();
	}
	
	
}
